package com.wcbdota.ui;

import com.wcbdota.R;
import com.wcbdota.base.BaseUi;
import com.wcbdota.util.UIUtil;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.Toast;

public class UiHost extends BaseUi {
	Button mEquip,mHero,m1,m2,m3,m4,m5,mAdv,mCol,mLuntan;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.host);
		findView();
		setViewHW(mAdv,0.3,1);
		setViewHW(mHero,0.14,1);
		setViewHW(mEquip,0.12,1);
		setViewHW(mCol,0.12,1);
		setViewHW(mLuntan,0.12,1);
	}
	
	@Override
	public void onStart() {
		super.onStart();
		useView();
	}
	
	private void findView(){
		mHero=(Button) findViewById(R.id.bu_hero);
		mEquip=(Button) findViewById(R.id.bu_equip);
		mAdv=(Button) findViewById(R.id.bu_adv );
		m1=(Button) findViewById(R.id.bu_1);
		m2=(Button) findViewById(R.id.bu_2);
		m3=(Button) findViewById(R.id.bu_3);
		m4=(Button) findViewById(R.id.bu_4);
		m5=(Button) findViewById(R.id.bu_5);
		mCol=(Button) findViewById(R.id.bu_collection);
		mLuntan=(Button) findViewById(R.id.bu_luntan);
	}
	
	private void useView(){
		mEquip.setOnClickListener(new ButtonListener());
		mHero.setOnClickListener(new ButtonListener());
		mAdv.setOnClickListener(new ButtonListener());
		m1.setOnClickListener(new ButtonListener());
		m2.setOnClickListener(new ButtonListener());
		m3.setOnClickListener(new ButtonListener());
		m5.setOnClickListener(new ButtonListener());
		m4.setOnClickListener(new ButtonListener());
		mCol.setOnClickListener(new ButtonListener());
		mLuntan.setOnClickListener(new ButtonListener());
		alphaValue(m1,m2,m3,m4,m5,200,80,80,80,80);
		mAdv.setBackgroundResource(R.drawable.advc);
	}
	
	class ButtonListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			switch(v.getId()){
			case R.id.bu_hero:
				Intent ihero = new Intent(UiHost.this,UiHero.class);
				startActivity(ihero);
				break;
			case R.id.bu_1:
				mAdv.setBackgroundResource(R.drawable.advc);
				alphaValue(m1,m2,m3,m4,m5,200,80,80,80,80);
				break;
			case R.id.bu_2:
				mAdv.setBackgroundResource(R.drawable.adv);
				alphaValue(m1,m2,m3,m4,m5,80,200,80,80,80);
				break;
			case R.id.bu_3:
				mAdv.setBackgroundResource(R.drawable.adva);
				alphaValue(m1,m2,m3,m4,m5,80,80,200,80,80);
				break;
			case R.id.bu_4:
				mAdv.setBackgroundResource(R.drawable.advb);
				alphaValue(m1,m2,m3,m4,m5,80,80,80,200,80);
				break;
			case R.id.bu_5:
				mAdv.setBackgroundResource(R.drawable.advd);
				alphaValue(m1,m2,m3,m4,m5,80,80,80,80,200);
				break;
			case R.id.bu_equip:
				Intent iequip = new Intent(UiHost.this,UiItems.class);
				startActivity(iequip);
				break;
			case R.id.bu_collection:
				Toast.makeText(UiHost.this, "部分功能正在开发，尽请期待！", Toast.LENGTH_LONG).show();
				break;
			case R.id.bu_luntan :
				Toast.makeText(UiHost.this, "部分功能正在开发，尽请期待！", Toast.LENGTH_LONG).show();
				break;
			}
		}
	}
	
	//设定按钮透明度
	public void alphaValue(Button m1,Button m2,Button m3,Button m4,Button m5,
										int i1,int i2,int i3,int i4,int i5){
		m1.getBackground().setAlpha(i1);
		m2.getBackground().setAlpha(i2);
		m3.getBackground().setAlpha(i3);
		m4.getBackground().setAlpha(i4);
		m5.getBackground().setAlpha(i5);
	}
		
	//设定按钮大小占屏幕百分比
			public void setViewHW(View v,double Hratio,double Wratio){
				LayoutParams mLP;
				DisplayMetrics mMetrics = new DisplayMetrics();
				getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
				mLP=v.getLayoutParams();
				mLP.height=(int) (mMetrics.heightPixels*Hratio);
				mLP.width=(int) (mMetrics.widthPixels*Wratio);
				v.setLayoutParams(mLP);
			}

}
